﻿namespace EyeOpen.Security.Data.Nhibernate
{
    using System;
    using System.Collections.Generic;
    using EyeOpen.Security.Queries;
    using NHibernate;

    internal class QueryTranslator
    {
        public IEnumerable<TResult> ExecuteQuery<TSource, TResult>(ISession session, EyeOpen.Queries.IQuery<TSource, TResult> query)
        {
            if (query == null)
            {
                throw new ArgumentNullException("query");
            }

            if (session == null)
            {
                throw new ArgumentNullException("session");
            }

            if (query is UserByEmailAndPasswordQuery)
            {
                return
                    (IEnumerable<TResult>)
                    new UserByEmailAndPasswordQueryTranslator()
                    .Execute((UserByEmailAndPasswordQuery)query, session);
            }

            var message = string.Format("Query of type {0} is not supported.", query.GetType().Name);

            throw new NotSupportedException(message);
        }
    }
}
